package homework.day003;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 生成10个0-100的随机数并存入一个List集合中并输出
 * 之后将集合第3到第6个元素翻转并输出
 * 
 * @author Xiloer
 *
 */
public class Test04 {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        Random random = new Random();
        for (int i = 0; i < 10; i++) {
            int num = random.nextInt(101); // 生成0-100之间的随机整数
            list.add(num);
        }

        System.out.println("原始列表：" + list);

        if (list.size() >= 6) {
            // 翻转第3到第6个元素
            List<Integer> subList = list.subList(2, 6);
            for (int i = 0; i < subList.size() / 2; i++) {
                Integer temp = subList.get(i);
                int lastIndex = subList.size() - 1 - i;
                subList.set(i, subList.get(lastIndex));
                subList.set(lastIndex, temp);
            }
        }

        System.out.println("翻转后的列表：" + list);
    }
}

